package com.xxkj.drugtraceability.ui.start

import android.app.Application
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.os.Handler
import android.os.Message
import android.util.Log
import androidx.core.content.FileProvider
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.xxhis.drugtraceability.base.BaseViewModel
import com.xxkj.drugtraceability.bean.DrugPdaClientVersion
import com.xxkj.drugtraceability.bean.RequestBodyData
import com.xxkj.drugtraceability.net.DownFileByWebRequest
import com.xxkj.drugtraceability.net.Result
import com.xxkj.drugtraceability.net.WanService.Companion.BASE_URL_API
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.io.*
import java.net.URLDecoder
import java.net.URLEncoder

/**
 * author: zhoujingjin
 * created on: 2024/9/20 10:25
 * description:
 */
class StartViewModel(application: Application,private val startRepository: StartRepository):BaseViewModel(application) {
    var upType = MutableLiveData(-1)
    var drugPdaClientVersion : DrugPdaClientVersion? = null
    fun checkVersion(data:String){
        viewModelScope.launch(Dispatchers.Main) {
            withContext(Dispatchers.IO) {
                val result = startRepository.checkVersion(data)
                if (result is Result.Success){
                    if(result.data.data.isNeedUpdata){
                        //需要升级
                        upType.postValue(1)
                        drugPdaClientVersion = result.data.data.drugPdaClientVersion
                    }else{
                        //不需要升级直接往下走
                        upType.postValue(2)
                    }
                }else if (result is Result.Error){
                    upType.postValue(2)
                }
            }}
    }
}